package pub.guoxin.oops.common.auth.utils;

import lombok.Getter;
import org.springframework.mobile.device.Device;

/**
 * Created by guoxin on 17-11-11.
 */
@Getter
public enum DeviceAudienceEnum {
    AUDIENCE_UNKNOWN("unknown"),
    AUDIENCE_WEB("web"),
    AUDIENCE_MOBILE("mobile"),
    AUDIENCE_TABLET("tablet");

    private String value;

    DeviceAudienceEnum(String value) {
        this.value = value;
    }

    /**
     * 检查设备类型
     *
     * @param device
     * @return
     */
    public static DeviceAudienceEnum checkDevice(Device device) {
        if (device.isMobile())
            return AUDIENCE_MOBILE;
        if (device.isTablet())
            return AUDIENCE_TABLET;
        if (device.isNormal())
            return AUDIENCE_WEB;
        return AUDIENCE_UNKNOWN;
    }

}
